package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * Path： /admin/order/conditionSearch
     *管理端分页查询订单
     * Method： GET
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单分页管理，{}",ordersPageQueryDTO);
        final PageResult page = orderService.pageAdmin(ordersPageQueryDTO);
        return Result.success(page);
    }
    /**
     * Path： /admin/order/details/{id}
     *管理端按id查看订单
     * Method： GET
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> FindById(@PathVariable Long id){
        log.info("查询订单详情，{}",id);
        OrderVO orderVO=orderService.FindById(id);
        return Result.success(orderVO);
    }
    /**
     * Path： /admin/order/cancel
     *取消订单
     * Method： PUT
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result Cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("取消订单");
        orderService.Cancel(ordersCancelDTO);
        return Result.success();
    }
    /**
     * 派送中订单
     */
    @GetMapping("statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> Total() {
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO orderStatisticsVO=orderService.Total();
        return Result.success(orderStatisticsVO);
    }
    /**
     * 派送订单
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("将订单改为派送中")
    public Result send(@PathVariable Long id) {
        log.info("将订单派送");
        orderService.send(id);
        return Result.success();
    }
    /**
     * 送达订单
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("将订单改为派送中")
    public Result Finish(@PathVariable Long id) {
        log.info("将订单派送");
        orderService.finish(id);
        return Result.success();
    }
    /**
     * 接单
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result Get(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("接单，{}",ordersConfirmDTO);
        orderService.get(ordersConfirmDTO);
        return Result.success();
    }
    /**
     * 拒单
     */
    @PutMapping("rejection")
    @ApiOperation("拒单")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("拒单，{}",ordersRejectionDTO);
        orderService.reject(ordersRejectionDTO);
        return Result.success();
    }
}
